
function main() {    
    try {
        var responseXml = CallCrmService(GetSoapXml());
        var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
        xmlDoc.async = false;
        xmlDoc.loadXML(responseXml);
        var resultCount = xmlDoc.documentElement.firstChild.firstChild.firstChild.firstChild.childNodes.length;
        var displayCount = 0;
        var gridHtml = '';
        gridHtml += GRID_HEADER;
        for (i = 0; i < resultCount; ++i) {
            var itemXml = xmlDoc.documentElement.firstChild.firstChild.firstChild.firstChild.childNodes[i];

            var activityId = itemXml.selectSingleNode('q1:activityid').text;
            var activityType = itemXml.selectSingleNode('q1:activitytypecode').text;
            var activitySubject = itemXml.selectSingleNode('q1:subject').text;

            var activityDate = "";
            if (itemXml.selectSingleNode('q1:scheduledend') != undefined) {
                activityDate = itemXml.selectSingleNode('q1:scheduledend').getAttribute("date");
                var activityTime = itemXml.selectSingleNode('q1:scheduledend').getAttribute("time");
                if (activityTime != "00:00") activityDate += " - " + activityTime;
            }

            var parentId = "";
            var parentType = "";
            var parentName = "";
            var parentXml = itemXml.selectSingleNode('q1:regardingobjectid');
            if (parentXml != undefined) {
                parentId = parentXml.text;
                parentType = parentXml.getAttribute("type");
                parentName = parentXml.getAttribute("name");
            }
            
            var addFlag = false;
            if (SHOW_TASK && activityType == "task") addFlag = true;
            if (SHOW_FAX && activityType == "fax") addFlag = true;
            if (SHOW_EMAIL && activityType == "email") addFlag = true;
            if (SHOW_PHONECALL && activityType == "phonecall") addFlag = true;
            if (SHOW_APPOINTMENT && activityType == "appointment") addFlag = true;
            if (SHOW_LETTER && activityType == "letter") addFlag = true;
            if (SHOW_SERVICEAPPOINTMENT && activityType == "serviceappointment") addFlag = true;
            if (SHOW_CAMPAIGNRESPONSE && activityType == "campaignresponse") addFlag = true;
            if (SHOW_CAMPAIGNACTIVITY && activityType == "campaignactivity") addFlag = true;
                        
            if (addFlag) {
                gridHtml += ROW_HEADER;
                gridHtml += GetRow(activityId, activityType, GetEntityName(activityType), activitySubject, activityDate, parentId, parentType, GetEntityName(parentType) + ": " + parentName);
                gridHtml += ROW_FOOTER;
                ++displayCount;
            }
        }
        gridHtml += GRID_FOOTER;

        data.innerHTML = gridHtml;
        footer.innerHTML = "Activities: " + displayCount;

        if (displayCount > 8) headerDate.width = 58;
        else headerDate.width = 42;       
    }
    catch (error) {
        data.innerHTML = "<div align='center'><br /><br /><br />No connection to the CRM server.</div>";
        footer.innerHTML = "";
    }
}
     